package com.xuecheng.content.api;

import com.xuecheng.content.mapper.TeachplanMapper;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.model.dto.UploadMediaDto;
import com.xuecheng.content.model.po.Teachplan;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 */
@Api(value = "课程计划编辑接口",tags = "课程计划编辑接口")
@RestController
@Slf4j
@RequestMapping("/teachplan")
public class TeachplanController {
    @Autowired
    private TeachplanService teachplanService;
    @Resource
    TeachplanMapper teachplanMapper;

    @GetMapping("/{teachplanId}")
    @ApiOperation("按课程计划id查课程计划")
    Teachplan getTeachPlanByTeachplanId(@PathVariable("teachplanId") Long teachplanId){
        return teachplanMapper.selectById(teachplanId);
    }

    @PostMapping("/association/media")
    @ApiOperation("课程计划绑定媒资")
    public void uploadmedia(@RequestBody UploadMediaDto uploadMediaDto){
        teachplanService.uploadmedia(uploadMediaDto);
    }
    @DeleteMapping("/association/media/{teachplanId}/{mediaId}")
    @ApiOperation("删除课程计划绑定媒资")
    public void deleteTeachplanMedia(@PathVariable("teachplanId")Long teachplanId,@PathVariable("mediaId")String mediaId){
        teachplanService.deleteTeachplanMedia(teachplanId,mediaId);
    }

    @ApiOperation("查询课程计划树形结构接口")
    @ApiImplicitParam(value = "courseId",name = "课程Id",required = true,dataType = "Long",paramType = "path")
    @GetMapping("/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId){

        return teachplanService.getTreeNodes(courseId);
    }

    @ApiOperation("课程计划创建或修改接口")
    @PostMapping
    public void saveTeachplan(@RequestBody SaveTeachplanDto teachplan){

        teachplanService.saveTeachplan(teachplan);
    }

    @ApiOperation("课程计划删除")
    @DeleteMapping("/{teachplanId}")
    public void deleteTeachplan(@PathVariable Long teachplanId){
        teachplanService.deleteTeachplan(teachplanId);
    }

    @ApiOperation("课程计划下移")
    @PostMapping("/movedown/{teachplanId}")
    public void movedownTeachplan(@PathVariable Long teachplanId){
        log.info("课程计划下移");
        teachplanService.movedownTeachplan(teachplanId);
    }


    @ApiOperation("课程计划上移")
    @PostMapping("/moveup/{teachplanId}")
    public void moveupTeachplan(@PathVariable Long teachplanId){
        log.info("课程计划上移");
        teachplanService.moveupTeachplan(teachplanId);
    }


}
